1. /* sdmround.cpp by K.Tsuru */
  2. // function ID = 342 DRADIX, BRADIX
  3. /******************************************************************************
  4. SDouble class
  5. It provides the rounding off to the last effective figure.
  6. At the top of hidden figures it rounds up numbers of radix/2 and above and drops
  7. anything under radix/2.It is used in the output function, etc.
  8. It executes in the case size==MaxSize(). It does not use CurrentMaxSize().
  9. When std==1 it converts into the standard from.
  10. default : std = 1
  11. *******************************************************************************/
  12. #ifndef SN_H
  13. #include "sn.h"
  14. #endif
  15. SDouble& SDouble::Round(int std){
  16. //conversion into standard form, SDouble only
  17. if( (Type() == REAL) && (std & STD_REF) ) StdReform(342);
  18. // 0.v[1] ...... v[eff]v[hdn]
  19. uint i, eff = MaxSize() - Hidden() -1u, rnd;
  20. if(aHead <= eff) return *this; //It has no hidden figure including 0.
  21. rnd = eff + 1u; //top position of the hidden figures
  22. if( figure(rnd) >= Radix()/2 ){
  23. figure[rnd-1]++;
  24. if(figure(rnd-1) >= Radix()) Normalize();
  25. if(figure(0) && (Type() == REAL)){
  26. // 0.99999....D^e --> 1.0000....D^e --> 0.1000.... D^(e+1)
  27. SetRdxExp(rdxExp+1); ShiftArray(1);
  28. }
  29. }
  30. //It cuts down the hidden figures.
  31. for(i = rnd; i<= aHead; i++) figure[i] = 0;
  32. if(aTail >= rnd){
  33. //It becomes zero by cutting down in the fixed point mode.
  34. SetZero(); return *this;
  35. }
  36. //It gets the figure positions."aTail" is not changed.
  37. i = rnd-1;
  38. const fType* fp = figure.Elements();
  39. while( !fp[i] ) i--;
  40. #ifndef NDEBUG
  41. figure(i);
  42. #endif
  43. aHead = i;
  44. //It converts into the standard form again for the reduction of the size, etc.
  45. //0.abcd efgh 0000 .... 0000 hhhh hhhh --> 0.abcd efgh 0000 .... 0000
  46. if( (Type() == REAL) && (std & STD_REF) ) StdReform(342);
  47. return *this;
  48. }

sdmround.cpp : last modifiled at 2017/03/13 14:31:57(1,850 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).